package com.valuegroup.smarttodo.ui.programme.goals;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.valuegroup.smarttodo.R;
import com.valuegroup.smarttodo.data.vo.BranchVo;

import java.util.List;

import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 课时列表(属于课程子集)
 */
public class GoalsTraceSourceBranchAdapter extends RecyclerView.Adapter {

    private static final String TAG = GoalsTraceSourceBranchAdapter.class.getSimpleName();

    private List<BranchVo> itemList;

    public GoalsTraceSourceBranchAdapter(List<BranchVo> itemList) {
        this.itemList = itemList;
    }

    @Override
    public int getItemCount() {
        return itemList.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        return new ItemViewHolder(LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_goals_trace_source_child, viewGroup, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ItemViewHolder v = (ItemViewHolder) holder;
        v.initData(itemList.get(position));
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.labTitle)
        TextView labTitle;
        @BindView(R.id.tagFinish)
        ImageView tagFinish;

        private BranchVo data;

        public ItemViewHolder(final View v) {
            super(v);
            ButterKnife.bind(this, v);
        }

        public void initData(BranchVo data) {
            this.data = data;
            labTitle.setText(data.getTitle());
            tagFinish.setVisibility(data.isShowFinish() ? View.VISIBLE : View.GONE);
        }
    }
}
